//
//  HELSepcialistDtailHeaderCell.m
//  NursingAssociation
//
//  Created by wsj2015 on 2017/3/13.
//  Copyright © 2017年 wsj2015. All rights reserved.
//

#import "HELSepcialistDtailHeaderCell.h"
#import "UIImageView+BTimageView.h"
#import "DGSAttributedStringSuite.h"
#import "UILabel+labelTextContent.h"
#import "WSJTipTool.h"
@implementation HELSepcialistDtailHeaderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
 
    //    点击关注后,可以在我的专家查看哦~
    [WSJTipTool showTipForFunction:@"like_specilist" withWords:@"点击关注后,可以在\n我的专家查看哦~" withView:self.likeBtn.superview fromFrame:self.likeBtn.frame direction:AMPopTipDirectionLeft];
 
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)setModel:(HELSecoalistModel *)model{
   
    _model = model;
    
    
 
    
    
    [self.avatar nc_setImageWithUrl:model.imageUrl];
    
    self.nameL.text = model.lecturerName;
    self.hospitalL.text = model.unitName;
  
    NSAttributedString  *str =[NSAttributedString dgs_makeString:^(DGSAttributedStringMaker *add) {
        add.string(model.introduce?model.introduce:@"暂无简介")
        .color(kTxtColor).fontSize(14);
    }];
    
    self.introL.attributedText = str;
    self.likeBtn.selected = [model.isFollow integerValue];

    [self.introL changeSpacewithLineSpace:6 WordSpace:1];
    NSArray *lineArr2 = [self.introL getLinesArrayOfStringInLabel];
    [self.introL.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [self.introL removeGestureRecognizer:obj];
    }];
    if (lineArr2.count>4) {
        [self.introL expendWithIsexpend:model.isExpendIntroduce withDefaultNumberOfline:4];
        UITapGestureRecognizer *tapSkill = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(expendIntroLabelAction)];
        [self.introL addGestureRecognizer:tapSkill];
    }else{
      
    }
    [self layoutIfNeeded];
}

- (void)expendIntroLabelAction{
    self.model.isExpendIntroduce = !self.model.isExpendIntroduce;
    
    if (self.model.isExpendIntroduce) {
        self.introL.numberOfLines = 0;
    }else{
        self.introL.numberOfLines = 4;
    }
    if (self.expendBlock) {
        self.expendBlock();
    }
    
    
}


- (IBAction)likeAction:(UIButton *)sender {
    
    [WSJTipTool hideWithPopWithSupview:self.likeBtn.superview];
    [self animationWith:sender.layer];
    
    if (self.likeBlock) {
        self.likeBlock();
    }
}

- (void)animationWith:(CALayer *)layer{
    [UIView animateWithDuration:.8
                          delay:0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         //你想绕哪个轴哪个轴就为 1，其中的参数（角度， x, y, z）
                         
                         layer.affineTransform = CGAffineTransformScale(layer.affineTransform, 2, 2);
                       
                         
                         
                     }
                     completion:^(BOOL finished) {
                        self.likeBtn.selected = !self.likeBtn.selected;
                         [UIView animateWithDuration:.8 delay:0 usingSpringWithDamping:.6 initialSpringVelocity:.6 options:UIViewAnimationOptionCurveEaseIn animations:^{
                             layer.affineTransform = CGAffineTransformIdentity;
                         } completion:^(BOOL finished) {
                             
                         }];
                         
                     }];
}




@end
